<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------
use think\Container;
// 应用公共文件
/**
 * 获取对象实例
 * @param string $route
 * @param string $layer
 * @param array $vars
 * @return object
 */
function make($route='',$layer='model',$vars=[]){
    //当且仅当只有一个'/'和$layer不等于false时才使用标准分层机制,不然使用普通路径
    if(substr_count($route,'/')==1 && $layer !== false){
        $route=str_replace('/','/'.$layer.'/',$route);
    };
    //获取类的实际路径,起别名
    $route=str_replace('/','\\',$route);
    $abstract='app_'.$route;
    //绑定别名并获取实例
    if(!Container::getInstance()->bound($abstract)){
        return Container::getInstance()->set($abstract,'app\\'.$route)->get($abstract,$vars);
    }
    return Container::getInstance()->get($abstract,$vars);
}

/**
 * 获取核心数据模块core中的对象实例
 * @param string $route
 * @param string $layer
 * @param array $vars
 * @return object
 */
function core($route='',$layer='model',$vars=[]){
    //当且仅当只有一个'/'和$layer不等于false时才使用标准分层机制,不然使用普通路径
    if(substr_count($route,'/')==1 && $layer){
        $route=str_replace('/','/'.$layer.'/',$route);
    };
    //获取类的实际路径,起别名
    $route=str_replace('/','\\',$route);
    $abstract='app_core_'.$route;
    //绑定别名并获取实例
    if(!Container::getInstance()->bound($abstract)){
        return Container::getInstance()->set($abstract,'app\\core\\'.$route)->get($abstract,$vars);
    }
    return Container::getInstance()->get($abstract,$vars);
}
